home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / os2 / wuz11a.zip / WUZ.CMD < prev    next >
OS/2 REXX Batch file  |  1994-02-07  |  6KB  |  238 lines

  1. /* unzip/arj/pac etc and open folder */
  2. /* (c) Copyright 1994 Scott Maxwell. */
  3.  
  4. Drive    = 'E:'
  5. DestPath = 'E:\Download\temp\'
  6. IconPath = 'E:\Download'
  7.  
  8. KeepCommandLineWindow = 0
  9. WaitForUnzip = 1
  10. UnzipInCommandLineWindow = 1    /* KeepCommandLineWindow must be 1 for this */
  11.  
  12. arg Name ExtractHere
  13. if Name = '' then SIGNAL ShowUsage
  14. CurrentDir = Directory()
  15. DeferToPostWuz = 0
  16.  
  17. if KeepCommandLineWindow = 1 & UnzipInCommandLineWindow = 1 & ExtractHere \= "HERE" then
  18.   stub="preparing to extract"
  19. else
  20.   stub="extracting"
  21. Say '0a'x"WPS Unzip -" stub Name
  22. Say "(c) Copyright 1994 Scott Maxwell"'0a'x
  23.  
  24. Yes    = 1
  25. No     = 0
  26.  
  27. Extractor.    = ''
  28. CopyTo.       = No
  29. Update.          = ''
  30. UpdateP.      = ''
  31. Fresh.        = ''
  32.  
  33. Extractor.ARC = '@arc xo'
  34. Fresh.ARC     = '@arc f'
  35. Extractor.ARJ = '@unarj x'
  36. Extractor.LZH = '@lh x /s /o'
  37. Extractor.Z   = '@compress -d'
  38. CopyTo.Z      = Yes
  39. Extractor.TAR = '@tar xf'
  40. CopyTo.TAR    = Yes
  41. Extractor.EXE = '@'
  42. CopyTo.EXE    = Yes
  43. Extractor.COM = '@'
  44. CopyTo.COM    = Yes
  45. Extractor.CMD = '@'
  46. CopyTo.CMD    = Yes
  47. Extractor.BAT = '@'
  48. CopyTo.BAT    = Yes
  49. Extractor.ZIF = '@unzip -o -d'
  50. Extractor.ZIP = '@unzip -o -d'
  51. Update.ZIP    = '@zip -r -u'
  52. UpdateP.ZIP   = '-x zclr.cmd zupdate.cmd zfresh.cmd'
  53. Fresh.ZIP     = '@zip -r -f'
  54.  
  55. Extractor.ZOO = '@zoo x'
  56. CopyTo.ZOO    = No
  57.  
  58. call GetDriveSpec Name
  59. if Ext="" then do
  60.   Name=Name'\'NameOnly'.Zif'
  61.   call GetDriveSpec Name
  62. end
  63.  
  64. if Length(CHARIN(Name,1,1)) \= 1 then do
  65.    say Name 'not found.'"0a"x
  66.    '@pause'
  67.    exit(1)
  68.    END
  69. Call CHAROUT(Name)
  70.  
  71. if NameOnly="" | Ext="" then SIGNAL ShowUsage
  72.  
  73. if Extractor.Ext = '' then Ext="ZIP"
  74.  
  75. if ExtractHere = "HERE" then do
  76.   if CopyTo.Ext = Yes then do
  77.     '@copy' FullPath FullName'> nul'
  78.     '@attrib -r -h -s' FullName '> nul'
  79.     Param1 = FullName
  80.   end
  81.   else
  82.     Param1 = FullPath
  83.   Extractor.Ext Param1
  84.   if CopyTo.Ext = Yes then do
  85.     hold = FullPath
  86.     call GetDriveSpec FullName
  87.     if FullPath \= hold then
  88.       Call SysFileDelete Param1
  89.   end
  90.   exit(0)
  91. end
  92.  
  93. if Ext="ZIF" then do
  94.   dir.1 = directory()
  95.   dir.2 = directory(Left(FullPath,2))
  96.   FullPath = Left(FullPath,Length(FullPath)-Length(FullName)-1)
  97.   Call Directory FullPath
  98.   Extractor.Ext FullName
  99.   call RxFuncAdd 'SysSetObjectData','RexxUtil','SysSetObjectData'
  100.   Call SysSetObjectData FullPath,"ICONFILE="IconPath"FldUnZip.Ico"
  101.   Call Directory dir.2
  102.   Call Directory dir.1
  103.   exit(0)
  104. end
  105.  
  106. Dest=DestPath||NameOnly
  107.  
  108. CALL RxFuncAdd 'SysMkDir','RexxUtil','SysMkDir'
  109. CALL SysMkDir Dest
  110.  
  111. CALL RxFuncAdd 'SysFileDelete','RexxUtil','SysFileDelete'
  112. Call SysFileDelete Dest'\zclr.cmd'
  113.  
  114. Call CHAROUT Dest'\zclr.cmd',"@cd .."'0d'x'0a'x
  115. Call CHAROUT Dest'\zclr.cmd',"@detach Kill-Dir" Dest "> nul"'0d'x'0a'x
  116. Call CHAROUT Dest'\zclr.cmd',"@if '%1'=='-x' exit"'0d'x'0a'x
  117. Call CHAROUT Dest'\zclr.cmd'
  118. '@attrib +h' Dest'\zclr.cmd > nul'
  119.  
  120. if Update.Ext \= '' then do
  121.   Call SysFileDelete Dest'\zupdate.cmd'
  122.   Call CHAROUT Dest'\zupdate.cmd','@zipstrip' FullPath'0d'x'0a'x
  123.   Call CHAROUT Dest'\zupdate.cmd',Update.Ext FullPath '*' UpdateP.Ext
  124.   Call CHAROUT Dest'\zupdate.cmd'
  125.   '@attrib +h' Dest'\zupdate.cmd > nul'
  126. end
  127.  
  128. if Fresh.Ext \= '' then do
  129.   Call SysFileDelete Dest'\zfresh.cmd'
  130.   Call CHAROUT Dest'\zfresh.cmd',Fresh.Ext FullPath '*'
  131.   Call CHAROUT Dest'\zfresh.cmd'
  132.   '@attrib +h' Dest'\zfresh.cmd > nul'
  133. end
  134.  
  135. if WaitForUnzip = 0 then do
  136.   if KeepCommandLineWindow = 0 | UnzipInCommandLineWindow = 1 then
  137.     Call 'Open-Dir' Dest
  138.   else
  139.     if Check4OS2()=1 then
  140.       '@start "'NameOnly'.'Ext'" /l /fg post-wuz.cmd' Dest DeferToPostWuz Left(Fresh.Ext,1) Left(Update.Ext,1)
  141.     else
  142.       '@start "'NameOnly'.'Ext'" /f post-wuz.cmd' Dest DeferToPostWuz Left(Fresh.Ext,1) Left(Update.Ext,1)
  143. end
  144.  
  145.  
  146. holdDir = DIRECTORY(Drive)
  147. Call Directory(Dest)
  148.  
  149. if KeepCommandLineWindow = 0 | UnzipInCommandLineWindow = 0 then do
  150.   if CopyTo.Ext = Yes then do
  151.     '@copy' FullPath Dest '> nul'
  152.     '@attrib -r -h -s' FullName '> nul'
  153.     Param1 = FullName
  154.     end
  155.   else
  156.      Param1 = FullPath
  157.   Extractor.Ext Param1
  158.   if CopyTo.Ext = Yes then
  159.     Call SysFileDelete Param1
  160. end
  161.  
  162. if WaitForUnzip = 1 | UnzipInCommandLineWindow = 1 then do
  163.   if KeepCommandLineWindow = 0 then
  164.     Call 'Open-Dir' Dest
  165.   else do
  166.     if UnzipInCommandLineWindow = 1 then
  167.       DeferToPostWuz = FullPath
  168.     if Check4OS2()=1 then
  169.       '@start "'NameOnly'.'Ext'" /l /fg post-wuz.cmd' Dest DeferToPostWuz Left(Fresh.Ext,1) Left(Update.Ext,1)
  170.     else
  171.       '@start "'NameOnly'.'Ext'" /f post-wuz.cmd' Dest DeferToPostWuz Left(Fresh.Ext,1) Left(Update.Ext,1)
  172.   end
  173. end
  174.  
  175. Call Directory holdDir
  176. Call Directory CurrentDir
  177. exit(0)
  178.  
  179.  
  180.  
  181. GetDriveSpec: procedure expose FullPath FullName NameOnly Ext
  182. arg Name
  183. fDrive = FILESPEC('Drive',Name)
  184. fPath  = FILESPEC('Path',Name)
  185. fName  = FILESPEC('Name',Name)
  186.  
  187. Dir.1 = 'DIRECTORY'()
  188. if fDrive = '' then
  189.    fDrive = FILESPEC('Drive',Dir.1)
  190.  
  191. Dir.2 = DIRECTORY(fDrive)
  192. if fPath  = '' then
  193.    fPath  = FILESPEC('Path', Dir.2)
  194.  
  195. if Left(fPath,1) \= '\' then do
  196.    Dir.3 = directory(fPath)
  197.    fPath = FILESPEC('Path', Dir.3)
  198.    Call Directory Dir.2
  199.    end
  200. Call Directory Dir.1
  201.  
  202. FullPath = fDrive||fPath||fName
  203. FullName = fName
  204.  
  205. ExtPos = LASTPOS(".",fName)
  206. if ExtPos=0 then do
  207.    Ext = ''
  208.    NameOnly = fName
  209.    end
  210. else do
  211.    Ext = SUBSTR(fName,ExtPos+1)
  212.    NameOnly = LEFT(fName,ExtPos-1)
  213.    end
  214. return
  215.  
  216.  
  217. Directory: procedure
  218.   arg Name
  219.   if Length(Name) > 3 then
  220.     if Right(Name,1) = '\' then
  221.       Name = Left(Name,LENGTH(Name)-1)
  222.   n = 'DIRECTORY'(Name)
  223.   if Right(n,1) \= '\' then
  224.     n = n'\'
  225.   return n
  226.  
  227.  
  228. Check4OS2: procedure
  229.   '@set is4os2=%_4ver'
  230.   return DATATYPE(VALUE(is4os2,,OS2ENVIRONMENT),'N')
  231.  
  232.  
  233. ShowUsage:
  234.   say "USAGE: wuz filename.[ARJ|LZH|TAR|Z|ZIP|ZOO] here"
  235.   say "If you add 'here' after the filename, the archive will be expanded in place."'0a'x
  236.   '@pause'
  237.   exit
  238.